package com.sqfw.project.wpReport.service.impl;

import com.sqfw.project.system.domain.SysDictData;
import com.sqfw.project.system.mapper.SysDictDataMapper;
import com.sqfw.project.wp.domain.WpInfo;
import com.sqfw.project.wp.mapper.WpInfoMapper;
import com.sqfw.project.wpReport.domain.TagReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sqfw.project.wpReport.service.ITagReportService;

import java.util.ArrayList;
import java.util.List;

/**
 * 工单标签统计表Service业务层处理
 *
 * @author lx
 * @date 2023-08-03
 */
@Service
public class TagReportServiceImpl implements ITagReportService {
    @Autowired
    private SysDictDataMapper sysDictDataMapper;

    @Autowired
    private WpInfoMapper wpInfoMapper;

    private static final String dictType = "tag_name";

    @Override
    public List<TagReport> getTagReportList(TagReport tagReport) {

        List<TagReport> tagReports = new ArrayList<>();

        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictType(dictType);
        sysDictData.setDictLabel(tagReport.getTagName());
        //正常展示状态
        sysDictData.setStatus("0");
        List<SysDictData> dataList = sysDictDataMapper.selectDictDataList(sysDictData);

        if (dataList.size() == 0) {
            return tagReports;
        }
        WpInfo wpInfo = new WpInfo();
        wpInfo.setBegainTime(tagReport.getBegainTime());
        wpInfo.setEndTime(tagReport.getEndTime());

        for (SysDictData dictData : dataList) {
            TagReport report = new TagReport();
            report.setTagName(dictData.getDictLabel());
            wpInfo.setDictData(dictData.getDictCode().toString());
            Integer count = wpInfoMapper.countWpInfoDictData(wpInfo);
            report.setCount(count);
            if (count > 0) {
                tagReports.add(report);
            }
        }
        return tagReports;
    }
}
